#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time      :2021/4/19 11:01
# @Author    :cjw
import unittest
from os.path import join
from setting.setting import CASE_PATH, REPORT_PATH
from util.utils import get_time, get_current_date
from common.HTMLTestRunner import HTMLTestRunner
from util.mail import Email
from common.logs import log


def school_web_case_run():
	"""案例执行"""
	suite = unittest.TestSuite()  # 测试套件初始化
	loader = unittest.defaultTestLoader  # 测试加载器初始化
	test_suite = loader.discover(CASE_PATH)
	suite.addTest(test_suite)

	report_name = get_time() + '_report.html'
	report_html_path = join(REPORT_PATH, report_name)
	with open(report_html_path, 'wb') as f:
		runner = HTMLTestRunner(
			f,
			verbosity=2,
			title='桃李云校web端自动化测试',
			description='主要包含学管和班主任角色的后台功能案例')
		runner.run(suite)

	# 发送邮件
	email = Email(
		title=f'桃李云校web端自动化测试_{get_current_date()}',
		receiver='xxx@163.com',
		message='主要包含学管和班主任角色的后台功能案例',
		attachment_file=report_html_path
	)
	email.send()
	log.info(f'用例执行完成，且已成功发送邮件！')


if __name__ == '__main__':
	school_web_case_run()
